package com.yxkj.railservicer.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.yxkj.railservicer.R;
import com.yxkj.railservicer.bean.QiangDanBean;
import com.yxkj.railservicer.pager.QiangDan;
import com.yxkj.railservicer.util.ContentUtil;

import java.util.List;

/**
 * Created by sunyu on 2017/2/28.
 */

public class QiangDanAdapter extends RecyclerView.Adapter<QiangDanAdapter.MyViewHolder> {
    private List<QiangDanBean> list;
    private Context context;
    private QiangDan qiangDan;

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView tv_qiangdan_firstTime;
        TextView tv_qiangdan_time;
        TextView tv_qiangdan_lasttime;
        ImageView iv_qiangdan_icon;
        TextView tv_qiangdan_order;
        TextView tv_qiangdan_name;
        TextView tv_qiangdan_address_get;
        TextView tv_qiangdan_address_post;
        Button btn_qiangdan;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv_qiangdan_firstTime = (TextView) itemView.findViewById(R.id.tv_qiangdan_firstTime);
            tv_qiangdan_time = (TextView) itemView.findViewById(R.id.tv_qiangdan_time);
            tv_qiangdan_lasttime = (TextView) itemView.findViewById(R.id.tv_qiangdan_lasttime);
            iv_qiangdan_icon = (ImageView) itemView.findViewById(R.id.iv_qiangdan_icon);
            tv_qiangdan_order = (TextView) itemView.findViewById(R.id.tv_qiangdan_order);
            tv_qiangdan_name = (TextView) itemView.findViewById(R.id.tv_qiangdan_name);
            tv_qiangdan_address_get = (TextView) itemView.findViewById(R.id.tv_qiangdan_address_get);
            tv_qiangdan_address_post = (TextView) itemView.findViewById(R.id.tv_qiangdan_address_post);
            btn_qiangdan = (Button) itemView.findViewById(R.id.btn_qiangdan);


        }
    }

    public QiangDanAdapter(Context context, List<QiangDanBean> list, QiangDan qiangDan) {
        this.context = context;
        this.list = list;
        this.qiangDan = qiangDan;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_qiangdan, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        QiangDanBean qiangDanBean = list.get(position);
        holder.tv_qiangdan_firstTime.setText(qiangDanBean.getFirst_time());
        holder.tv_qiangdan_time.setText(qiangDanBean.getTime());
        holder.tv_qiangdan_lasttime.setText(qiangDanBean.getLast_time());
        Picasso.with(context).load(qiangDanBean.getIcon()).into(holder.iv_qiangdan_icon);
        holder.tv_qiangdan_order.setText(qiangDanBean.getOrder());
//        holder.iv_qiangdan_icon.setImageResource(qiangDanBean.getIcon());
        holder.tv_qiangdan_name.setText(qiangDanBean.getName());
        holder.tv_qiangdan_address_get.setText(qiangDanBean.getAddressGet());
        holder.tv_qiangdan_address_post.setText(qiangDanBean.getAddressPost());

        holder.btn_qiangdan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                qiangDan.acceptOrder(position);
            }
        });
    }
}
